//
//  MIME.m
//  iGSS
//
//  Copyright 2010 Electronic Business Systems Ltd.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import "MIME.h"

NSSet *viewableTypes;
NSDictionary *iconNames;

@implementation MIME

+ (void)initialize {
	
	viewableTypes = [[NSSet alloc] initWithObjects:
					 @"application/msword",
					 @"application/pdf",
					 @"application/vnd.ms-excel",
					 @"application/vnd.ms-powerpoint",
					 @"image",
					 @"text",
					 nil];
	
	iconNames = [[NSDictionary alloc] initWithObjectsAndKeys:
				 @"48px-X-office-document.svg.png",		@"application/msword",
				 @"48px-X-office-document.svg.png",		@"application/pdf", 
				 @"48px-X-office-spreadsheet.svg.png",	@"application/vnd.ms-excel",
				 @"48px-X-office-presentation.svg.png", @"application/vnd.ms-powerpoint",
				 @"48px-Image-x-generic.svg.png",		@"image",
				 @"48px-Text-x-generic.svg.png",		@"text",
				 @"48px-Text-x-generic.svg.png",		@"text/html",
				 @"48px-X-office-document.svg.png",		@"text/rtf",
				 nil];
}

+ (BOOL)canDisplayType:(NSString *)type {
	BOOL viewable = [viewableTypes containsObject:type];
	if (!viewable)
		viewable = [viewableTypes containsObject:[type stringByDeletingLastPathComponent]];
	return viewable;
}

+ (UIImage *)iconForType:(NSString *)type {
	NSString *name = [iconNames objectForKey:type];
	if (!name)
		name = [iconNames objectForKey:[type stringByDeletingLastPathComponent]];
	if (!name)
		name = @"48px-File-generic.png";
	return [UIImage imageNamed:name];
}

@end
